//
//  AddressListVC.m
//  ChangChat
//
//  Created by Cocoa on 2019/8/20.
//  Copyright © 2019 yibai. All rights reserved.
//

#import "AddressListVC.h"
#import "FriendCell.h"
#import "SCIndexView.h"
#import "UITableView+SCIndexView.h"
#import "FriendInfoListVC.h"
#import "YCMenuView.h"
#import "FriendListHeaderView.h"
#import "SearchFriendResultVC.h"
#import "DIYScanVC.h"
#import <WZLBadgeImport.h>
#import "IMManager.h"
#import "MineListVC.h"
#import "GroupListVC.h"

@interface AddressListVC ()<IMManagerDelegate, SCTableViewSectionIndexDelegate>
@property (nonatomic, strong) NSArray *sectionTitles;
//@property (nonatomic, strong) SCIndexView *indexView;
@property (nonatomic, strong) FriendListHeaderView *headView;

@property (nonatomic, strong) UISearchController *searchVC;
@property (nonatomic, weak) SearchFriendResultVC *resultVC;
@property (nonatomic, assign) CFRunLoopObserverRef observerRef;

@property (nonatomic, strong) NSMutableArray *selectedFriendIdsArryay;
@end

@implementation AddressListVC
- (void)dealloc
{
    if (self.observerRef) {
        CFRunLoopRemoveObserver(CFRunLoopGetMain(), self.observerRef, kCFRunLoopDefaultMode);
    }
    
}
- (void)viewDidLoad {
    [super viewDidLoad];

    [self setupUI];
//    self.title = @"新朋友";
    self.navigationItem.title = @"通讯录";
    if (self.listType < 2) {
        [self setupSearchVc];
    }
    [self updateTableView];
    
    [[IMManager shareManager] addIMDelegate:self];
    
    
    @weakify(self);
    [[[[NSNotificationCenter defaultCenter] rac_addObserverForName:notificaiton_FriendList_updated object:nil] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(NSNotification * _Nullable x) {
        @strongify(self);
        [self updateTableView];
    }];
    
    [[[[NSNotificationCenter defaultCenter] rac_addObserverForName:notification_Friend_Info_Changed object:nil] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(NSNotification * _Nullable x) {
        @strongify(self);
        FriendItem *item = x.object;
        for (YBContentModel *content in self.dataSource) {
            for (FriendItem *friend  in content.item) {
                if ([friend.friend_id isEqualToString:item.friend_id] == YES) {
                    
                    NSIndexPath *indexpath = [NSIndexPath indexPathForRow:[content.item indexOfObject:friend] inSection:[self.dataSource indexOfObject:content]];
                    friend.nickname = item.nickname;
                    friend.avatar = item.avatar;
                    friend.username = item.username;
                    [self.tableView reloadRowsAtIndexPaths:@[indexpath] withRowAnimation:UITableViewRowAnimationNone];
                    break;
                }
            }
        }
    }];
}

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    
    [self.tabBarItem clearBadge];
    [FileUtils deleteObjectFromUserDefaultWithKey:@"new_friend_agree"];
}

- (void)setupUI {
    [self.tableView customRegisterClassWithName:@"FriendCell"];
    
    SCIndexViewConfiguration *cfg = [SCIndexViewConfiguration configurationWithIndexViewStyle:SCIndexViewStyleCenterToast];
    self.tableView.sc_indexViewConfiguration = cfg;
    self.tableView.sc_translucentForTableViewInNavigationBar = self.navigationController.navigationBar.translucent;
    self.tableView.sc_indexViewDelegate = self;
    
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    if (self.listType == 1) {
        self.navigationItem.title = @"选择联系人";
        btn.k_title(@"取消").k_titleColor(UIColor.whiteColor);
        [btn addTarget:self action:@selector(handleBackItemAction) forControlEvents:UIControlEventTouchUpInside];
        self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:btn];
    } else if (self.listType == 2) {
        self.navigationItem.title = @"发起群聊";
        btn.k_title(@"取消").k_titleColor(UIColor.whiteColor);
        [btn addTarget:self action:@selector(handleBackItemAction) forControlEvents:UIControlEventTouchUpInside];
        self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:btn];
        btn = [UIButton buttonWithType:UIButtonTypeCustom];
        btn.k_title(@"确认").k_titleColor(UIColor.whiteColor);
        [btn addTarget:self action:@selector(createGroupChatAction) forControlEvents:UIControlEventTouchUpInside];
        self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:btn];
    } else if (self.listType == 3) {
        self.navigationItem.title = @"选择联系人";
        btn.k_title(@"取消").k_titleColor(UIColor.whiteColor);
        [btn addTarget:self action:@selector(handleBackItemAction) forControlEvents:UIControlEventTouchUpInside];
        self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:btn];
        btn = [UIButton buttonWithType:UIButtonTypeCustom];
        btn.k_title(@"确认").k_titleColor(UIColor.whiteColor);
        [btn addTarget:self action:@selector(groupChatAddUserAction) forControlEvents:UIControlEventTouchUpInside];
        self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:btn];
    }
    else {
        btn.k_img(UIImage.k_imgName(@"tab_plus"));
        [btn addTarget:self action:@selector(didClickRightBarBtnItemAction) forControlEvents:UIControlEventTouchUpInside];
        self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:btn];
        
        self.headView = [[FriendListHeaderView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 70)];
        self.tableView.tableHeaderView = self.headView;
        [self.headView layoutIfNeeded];
        self.tableView.tableHeaderView = self.headView;
        if ([[NSUserDefaults standardUserDefaults] integerForKey:@"new_friend_apply"] > 0) {
            [self.headView.nicknameLabel showBadgeWithStyle:WBadgeStyleRedDot value:0 animationType:WBadgeAnimTypeNone];
        }
        @weakify(self);
        [[self.headView.actionBtn rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
            @strongify(self);
            [self.tabBarItem clearBadge];
            [self.headView.nicknameLabel clearBadge];
            [FileUtils deleteObjectFromUserDefaultWithKey:@"new_friend_apply"];
            [self.navigationController pushViewController:[NSClassFromString(@"NewFriendListVC") new] animated:YES];
        }];
    }
}

- (void)tableView:(UITableView *)tableView didSelectIndexViewAtSection:(NSUInteger)section {
    if (tableView.contentSize.height < (ScreenSize.height - NavigationBarHeight - TabbarHeight)) {
        [tableView scrollsToTop];
    }
}
- (NSUInteger)sectionOfTableViewDidScroll:(UITableView *)tableView {
    return SCIndexViewInvalidSection;
}

- (void)setupSearchVc {
    
    self.extendedLayoutIncludesOpaqueBars = !self.navigationController.navigationBar.translucent;
    [[UIBarButtonItem appearanceWhenContainedInInstancesOfClasses:@[UISearchBar.class]] setTintColor:UIColor.k_t2Color];
    [[UIBarButtonItem appearanceWhenContainedInInstancesOfClasses:@[UISearchBar.class]] setTitle:@"取消"];

    SearchFriendResultVC *resultVC = [SearchFriendResultVC new];
    @weakify(self);
    [resultVC setDidSelectFriendItemBlock:^(FriendItem * _Nonnull item) {
        @strongify(self);
        if (self.listType == 1) {
            if (self.didSelectFriendItemBlock) {
                self.didSelectFriendItemBlock(item);
            }
        } else {
            [self showFriendInfoVCWithType:2 friendItem:item from:@"0"];
        }
    }];
    self.resultVC = resultVC;
    self.searchVC = [[UISearchController alloc] initWithSearchResultsController:resultVC];
    
    self.searchVC.searchResultsUpdater = resultVC;
    self.searchVC.searchBar.delegate = resultVC;
    self.searchVC.delegate = resultVC;
    
    // 1.设置placeholder
    self.searchVC.searchBar.placeholder = @"搜索好友";
    
    // 2.设置searchBar的背景透明
    [self.searchVC.searchBar setBackgroundImage:UIImage.k_imgFillColor(UIColor.whiteColor, CGSizeMake(ScreenWidth, 64))];
    self.searchVC.searchBar.searchBarStyle = UISearchBarStyleMinimal;
    
    // 3.设置搜索框文字的偏移
    self.searchVC.searchBar.searchTextPositionAdjustment = UIOffsetMake(3, 0);
    
    // 4.设置搜索框图标的偏移
//    CGFloat offsetX = (self.view.bounds.size.width - 200 - 32) / 2;
//    [self.searchVC.searchBar setPositionAdjustment:UIOffsetMake(offsetX, 0) forSearchBarIcon:UISearchBarIconSearch];
    
    // 5.取消按钮和文本框光标颜色
//    self.searchVC.searchBar.tintColor = UIColor.k_t1Color;
//    self.searchVC.searchBar.barTintColor = UIColor.k_t1Color;
    
    // 6.设置搜索文本框背景图片 [圆形的文本框只需要设置一张圆角图片就可以了]
    
    [self.searchVC.searchBar setSearchFieldBackgroundImage:[UIImage.k_imgFillColor(UIColor.k_hexColor(0xf0f0f0), CGSizeMake(ScreenWidth - 100, 36)) imageWithCornerRadius:36/2] forState:UIControlStateNormal];
    // 7.设置搜索按钮
    UIImage *searchImg = [[UIImage imageNamed:@"new_search"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    [self.searchVC.searchBar setImage:searchImg forSearchBarIcon:UISearchBarIconSearch state:UIControlStateNormal];
    
    [self.searchVC.searchBar sizeToFit];
    

    // 2.Install the search bar
//    if ([self.navigationItem respondsToSelector:@selector(setSearchController:)]) {
//        // 2.1 For iOS 11 and later, wo place the search bar in the navigation bar
//        if (@available(iOS 11.0, *)) {
//            self.navigationItem.searchController = self.searchVC;
//            // 2.2 Set the search bar visible all the time
//            self.navigationItem.hidesSearchBarWhenScrolling = NO;
//        }

        // 2.3 Hide line view
//        __weak typeof(self) weakSelf = self;
//        self.observerRef = CFRunLoopObserverCreateWithHandler(kCFAllocatorDefault, kCFRunLoopAllActivities, true, 0, ^(CFRunLoopObserverRef observer, CFRunLoopActivity activity) {
//
//            NSLog(@"kCFRunLoopBeforeWaiting");
//            BOOL targetView = [weakSelf barGroudView:weakSelf.navigationController.view];
//            if (targetView) {
//                CFRunLoopRemoveObserver(CFRunLoopGetMain(), observer, kCFRunLoopDefaultMode);
//            }
//        });
//        CFRunLoopAddObserver(CFRunLoopGetMain(), self.observerRef, kCFRunLoopDefaultMode);

//    } else {
        UIView *v = [[YBBaseView alloc] initWithFrame:self.searchVC.searchBar.bounds];
        [v addSubview:self.searchVC.searchBar];
    v.backgroundColor = UIColor.whiteColor;
    self.view.backgroundColor = self.navigationController.view.backgroundColor;
    [resultVC setViewWillPresentBlock:^{
        @strongify(self);
        self.view.backgroundColor = UIColor.whiteColor;
    }];
    [resultVC setViewWillDisPresentBlock:^{
        @strongify(self);
        self.view.backgroundColor = self.navigationController.view.backgroundColor;
    }];
        
        [self.view addSubview:v];
        [v mas_makeConstraints:^(MASConstraintMaker *make) {
            if (@available(iOS 11.0, *)) {
                make.top.equalTo(self.view.mas_safeAreaLayoutGuideTop);
            } else {
                make.top.mas_offset(0);
            }
            make.left.right.mas_offset(0);
            make.height.mas_equalTo(56);
        }];
        [self.tableView mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.left.bottom.right.mas_offset(0);
            make.top.equalTo(v.mas_bottom);
        }];
//    }

    // 3.It is usually good to set the presentation context
    self.definesPresentationContext = YES;
    
    // 8.拿到搜索文本框
    UITextField *searchField = [self.searchVC.searchBar valueForKey:@"_searchField"];
//    // 9.设置取消按钮文字
//    [self.searchVC.searchBar setValue:@"取消" forKey:@"_cancelButtonText"];
//
    searchField.font = [UIFont systemFontOfSize:14];
}
- (BOOL)barGroudView:(UIView *)targetView {
    for (UIView *sView in targetView.subviews) {
        if ([sView isKindOfClass:NSClassFromString(@"_UINavigationControllerPaletteClippingView")]) {
            if (sView.subviews.count > 0 && sView.subviews[0].subviews.count > 0 && sView.subviews[0].subviews[0].subviews.count > 1) {
                sView.subviews[0].subviews[0].subviews[1].hidden = YES;
                return YES;
            }
        }
    }
    
    return NO;
}

- (BOOL)stringContainsEmoji:(NSString *)string{
    __block BOOL returnValue = NO;
    [string enumerateSubstringsInRange:NSMakeRange(0, [string length])
                               options:NSStringEnumerationByComposedCharacterSequences
                            usingBlock:^(NSString *substring, NSRange substringRange, NSRange enclosingRange, BOOL *stop) {
                                const unichar hs = [substring characterAtIndex:0];
                                if (0xd800 <= hs && hs <= 0xdbff) {
                                    if (substring.length > 1) {
                                        const unichar ls = [substring characterAtIndex:1];
                                        const int uc = ((hs - 0xd800) * 0x400) + (ls - 0xdc00) + 0x10000;
                                        if ((0x1d000 <= uc && uc <= 0x1f77f) || (0x1F900 <= uc && uc <=0x1f9ff)){
                                            returnValue = YES;
                                        }
                                    }
                                } else if (substring.length > 1) {
                                    const unichar ls = [substring characterAtIndex:1];
                                    if (ls == 0x20e3) {
                                        returnValue = YES;
                                    }
                                } else {
                                    if (0x2100 <= hs && hs <= 0x27ff) {
                                        returnValue = YES;
                                    } else if (0x2B05 <= hs && hs <= 0x2b07) {
                                        returnValue = YES;
                                    } else if (0x2934 <= hs && hs <= 0x2935) {
                                        returnValue = YES;
                                    } else if (0x3297 <= hs && hs <= 0x3299) {
                                        returnValue = YES;
                                    } else if (hs == 0xa9 || hs == 0xae || hs == 0x303d || hs == 0x3030 || hs == 0x2b55 || hs == 0x2b1c || hs == 0x2b1b || hs == 0x2b50) {
                                        returnValue = YES;
                                    }else if (hs == 0x200d){
                                        returnValue = YES;
                                    }
                                }
                            }];
    return returnValue;
}
- (NSString *)converStrEmoji:(NSString *)emojiStr
{
    __block NSString *muStr = [[NSString alloc]initWithString:emojiStr];
    [emojiStr enumerateSubstringsInRange:NSMakeRange(0, emojiStr.length) options:NSStringEnumerationByComposedCharacterSequences usingBlock:^(NSString *substring, NSRange substringRange, NSRange enclosingRange, BOOL *stop) {
        if ([self stringContainsEmoji:substring]) {
            muStr = [muStr stringByReplacingOccurrencesOfString:substring withString:@""];
        }
    }];
    return muStr;
}
- (void)updateTableView {
    
  
    NSMutableArray *sectionArr = [NSMutableArray array];
    for (FriendItem *item in kUsermanager.friendArray) {
        if (self.listType >= 2) {
            BOOL isHas = NO;
            for (NSNumber *obj in self.group.all_users_id) {
                if (obj.integerValue == item.friend_id.integerValue) {
                    isHas = YES;
                    break;
                }
            }
            if (isHas == YES) {
                continue;
            }
        }
        NSString *pinyin = [self firstCharactorWithString:item.displayName];
        item.pinyin = pinyin;
        NSString *firstLetter = @"";
        pinyin = [self converStrEmoji:pinyin];
        if (pinyin.isHaveStr) {
            firstLetter = [pinyin substringToIndex:1];
            if (firstLetter.isHaveStr == NO) {
                firstLetter = @"#";
            }
        }
        char tempChar[10];
        strcpy(tempChar,(char *)[firstLetter UTF8String]);
        char p = tempChar[0];
        if (p > 'Z' || p < 'A') {
            firstLetter = @"#";
        }
        
        YBContentModel *model = nil;
        for (YBContentModel *obj in sectionArr) {
            if ([obj.key isEqualToString:firstLetter] == YES) {
                model = obj;
            }
        }
        if (model == nil) {
            model = [YBContentModel new];
            model.key = firstLetter;
            model.item = [NSMutableArray array];
            [sectionArr addObject:model];
        }
        [model.item addObject:item];
    }
    [sectionArr sortUsingComparator:^NSComparisonResult(YBContentModel *  _Nonnull obj1, YBContentModel *  _Nonnull obj2) {
        return [obj1.key compare: obj2.key];
    }];
    YBContentModel *obj = sectionArr.firstObject;
    if ([obj.key isEqualToString:@"#"] == YES) {
        [sectionArr removeObject:obj];
        [sectionArr addObject:obj];
    }
    for (YBContentModel *model in sectionArr) {
        NSMutableArray *items = model.item;
        [items sortUsingComparator:^NSComparisonResult(FriendItem *  _Nonnull obj1, FriendItem *  _Nonnull obj2) {
            return [obj1.pinyin compare:obj2.pinyin];
        }];
    }
    
    self.dataSource = sectionArr;
    self.sectionTitles = [self.dataSource.rac_sequence map:^id _Nullable(YBContentModel *  _Nullable value) {
        return value.key;
    }].array;
    
//    self.indexView.dataSource = self.sectionTitles;
//    [self.indexView reloadInputViews];
    self.tableView.sc_indexViewDataSource = self.sectionTitles;
    [self.tableView reloadData];
    
//    NSMutableArray *arr = [NSMutableArray array];
//    for (YBContentModel *model in self.dataSource) {
//        for (id obj in model.item) {
//            [arr addObject:obj];
//        }
//    }
//    self.resultVC.dataSource = arr;
}
- (NSString *)firstCharactorWithString:(NSString *)string
{
    NSMutableString *str = [NSMutableString stringWithString:string];
    CFStringTransform((CFMutableStringRef) str, NULL, kCFStringTransformMandarinLatin, NO);
    CFStringTransform((CFMutableStringRef)str, NULL, kCFStringTransformStripDiacritics, NO);
    NSString *pinYin = [str capitalizedString];
//    return [pinYin substringToIndex:1];
    return pinYin;
}


#pragma mark - tableview
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return self.dataSource.count;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    YBContentModel *models = self.dataSource[section];
    return [models.item count];
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 30;
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
    return self.sectionTitles[section];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    FriendCell *cell = [tableView dequeueReusableCellWithIdentifier:@"FriendCell" forIndexPath:indexPath];
    YBContentModel *model = self.dataSource[indexPath.section];
    FriendItem *friend = [model.item objectAtIndex:indexPath.row];
    cell.friendItem = friend;
    if (self.listType == 2 || self.listType == 3) {
        cell.selectBtn.selected = [self.selectedFriendIdsArryay containsObject:friend.friend_id];
    }
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    YBContentModel *model = self.dataSource[indexPath.section];
    FriendItem *friend = [model.item objectAtIndex:indexPath.row];
    
    if (self.listType == 1) {
        if (self.didSelectFriendItemBlock) {
            self.didSelectFriendItemBlock(friend);
        }
        return;
    }
    
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    if (self.listType == 2 || self.listType == 3) {
        
        FriendCell *cell = [tableView cellForRowAtIndexPath:indexPath];
        cell.selectBtn.selected = !cell.selectBtn.selected;
        if ([self.selectedFriendIdsArryay containsObject:friend.friend_id] == YES) {
            cell.selectBtn.selected = NO;
            [self.selectedFriendIdsArryay removeObject:friend.friend_id];
        } else {
            cell.selectBtn.selected = YES;
            [self.selectedFriendIdsArryay addObject:friend.friend_id];
        }
        return;
    }
    
//    if ([friend.friend_id isEqualToString:kUsermanager.me.ID] == YES) {
//        MineListVC *mineVC = MineListVC.new;
//        [self.navigationController pushViewController:mineVC animated:YES];
//        return;
//    }
    [self showFriendInfoVCWithType:2 friendItem:friend from:@"0"];
}

- (void)showFriendInfoVCWithType:(NSInteger)type friendItem:(FriendItem *)item from:(NSString *)from {
    FriendInfoListVC *VC = [FriendInfoListVC new];
    VC.user = item;
    VC.from = from;
    VC.listType = type;
    
    [self.navigationController pushViewController:VC animated:YES];
}

#pragma mark - actions
- (void)didClickRightBarBtnItemAction {
    
    @weakify(self);
    YCMenuAction *action1 = [YCMenuAction actionWithTitle:@"添加朋友" image:UIImage.k_imgName(@"new_add_normal") handler:^(YCMenuAction *action) {
        [self.navigationController pushViewController:[NSClassFromString(@"AddNewFriendVC") new] animated:YES];
    }];
    action1.highlightImage = UIImage.k_imgName(@"new_add_highlight");
    
    YCMenuAction *addGroupAction = [YCMenuAction actionWithTitle:@"发起群聊" image:UIImage.k_imgName(@"new_group_normal") handler:^(YCMenuAction *action) {
        [self.navigationController pushViewController:[NSClassFromString(@"AddNewFriendVC") new] animated:YES];
    }];
    addGroupAction.highlightImage = UIImage.k_imgName(@"new_group_highlight");
    
    YCMenuAction *action2 = [YCMenuAction actionWithTitle:@"扫一扫" image:UIImage.k_imgName(@"new_qr_normal") handler:^(YCMenuAction *action) {
        DIYScanVC *scanVC = [DIYScanVC new];
        
        @strongify(self);
        scanVC.scanResult = ^(NSString *result) {
            [self showFriendInfoVCWithType:2 friendItem:[FriendItem mj_objectWithKeyValues:result] from:@"1"];
        };
        [self.navigationController pushViewController:scanVC animated:YES];
    }];
    action2.highlightImage = UIImage.k_imgName(@"new_qr_highlight");
    
    YCMenuView *view = [YCMenuView menuWithActions:@[action1, action2] width:135 relyonView:self.navigationItem.rightBarButtonItem];
    view.textColor = UIColor.k_t2Color;
    
    [view show];
}
- (void)createGroupChatAction {
    if (self.selectedFriendIdsArryay.count < 2) {
        [LBXAlertAction showAlertWithTitle:@"提示" msg:@"发起群聊需选择2人以上" buttonsStatement:@[@"知道了"] chooseBlock:nil];
        return;
    }
    if (self.didClickCreateGroupChatBlock) {
        self.didClickCreateGroupChatBlock(self.selectedFriendIdsArryay);
        [self dismissViewControllerAnimated:YES completion:nil];
    }
}
- (void)groupChatAddUserAction {
    if (self.selectedFriendIdsArryay.count < 1) {
        [LBXAlertAction showAlertWithTitle:@"提示" msg:@"请选择联系人" buttonsStatement:@[@"知道了"] chooseBlock:nil];
        return;
    }
    if (self.didClickCreateGroupChatBlock) {
        self.didClickCreateGroupChatBlock(self.selectedFriendIdsArryay);
        [self dismissViewControllerAnimated:YES completion:nil];
    }
}
- (NSMutableArray *)selectedFriendIdsArryay {
    if (_selectedFriendIdsArryay == nil) {
        _selectedFriendIdsArryay = [NSMutableArray array];
    }
    return _selectedFriendIdsArryay;
}
#pragma IMManager delegate
- (void)imManager:(IMManager *)manager receiveFriendStatusMsg:(MsgItem *)msg {
    if (msg.type == MsgType_Friend_apply) {
        [self.headView.nicknameLabel showBadgeWithStyle:WBadgeStyleRedDot value:0 animationType:WBadgeAnimTypeNone];
    }
}

@end
